package com.ljq.software_springboot.softwareprogram.imp;

import com.ljq.software_springboot.softwareprogram.entity.GroupMessage;
import com.ljq.software_springboot.softwareprogram.mapper.GroupMessageMapper;
import com.ljq.software_springboot.softwareprogram.service.IGroupMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-29
 */
@Service
public class GroupMessageServiceImpl extends ServiceImpl<GroupMessageMapper, GroupMessage> implements IGroupMessageService {
    @Autowired
    private GroupMessageMapper groupMessageMapper;
    public List<GroupMessage> findmessage(int id){
        return  groupMessageMapper.getGroupMessages(id);
    }
    @Transactional
    public Boolean saveMessage(GroupMessage messageRequest) {
            GroupMessage message = new GroupMessage();
            message.setSenderId(messageRequest.getSenderId());
            message.setGroupId(messageRequest.getGroupId());
            message.setContent(messageRequest.getContent());
            message.setTimestamp(new Timestamp(System.currentTimeMillis()).toLocalDateTime());
            groupMessageMapper.insert(message);
            return true;
    }
}
